import static java.util.Collections.reverse;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: liangyuanzhang
 * Date: 2025-3-12
 * Time: 0:28
 */
//反转数组
    /*
    分为三个部分
    1. 先将整个数组进行反转
    2. 再将k前的部分反转
    3. 再将k后的部分反转
     */
public class Test {
    private void reverse(int[] nums,int begin,int end){
        for (int i = begin,j = end; i < j; i++,j--) {
            int tmp = nums[j];
            nums[j] = nums[i];
            nums[i] = tmp;
        }
    }
    public void rotate(int[] nums,int k){
        int n = nums.length;
        k %= n;
        reverse(nums,0,n-1);
        reverse(nums,0,k-1);
        reverse(nums,k,n-1);
    }
}
